#ifndef _FACTORY_H_
#define _FACTORY_H_
#ifdef WIN32
#include <WinSock2.h>
#else
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <arpa/inet.h>
#include <sys/unistd.h>
#include <sys/ioctl.h>
#include <sys/fcntl.h>
#define SOCKET int
#define closesocket close
#endif
#include "../smartx/include/define.h"
#include "../smartx/include/event.h"

class xbase{
public:
	xbase();
	~xbase();
public:
	virtual int  open(bool run,const char* ip,short port)=0;
	virtual void close()=0;
	virtual int  write(const char * buf,size_t len)=0;
	virtual int  read(char* buf, size_t len)=0;
	void setTarget( const char* ip, short port);

protected:
	SOCKET mysocket;
	struct sockaddr_in myaddr;
	struct sockaddr_in destaddr;

private:
	static winapi recvthread(void* lpParam);
	pthread_t m_hThread;
	int    m_nWorkTimes;
	event_handle m_workEvent;
protected:
	bool start();
	bool stop();
};

class CFactory{
public:
	static xbase * create(unsigned char type);
	static void destory( xbase * x );
};

#endif














